<!-- <style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style> -->
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
  components: {},
  data() {
    return {
      appWindow: window,
      form: {
        adminCount: 0,
        id: 0,
        name: "",
        remark: "",
        menuIds: [],
        platformId: [],
      },
      // 页面接口地址
      apiUrl: {
        create: "mall-site-portal/ums-role/create",
        update: "mall-site-portal/ums-role/update",
        detail: "mall-site-portal/ums-role/getItem",
      },
      listCanAuthRole: [],
      menuIds: [58,90],
      isMobile: false,
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  methods: {
    // 初始化
    async init() {
      await this.mixinEdit_editBoxInit({
        model: "form",
        id: this.id,
        onInit: async () => {
          // 获取用户信息
          let _data = await this.$vFN.Http.post({
            url: "mall-site-portal/ums-role/listCanAuthMenu",
          },window);
          if (_data._ok) {
            this.listCanAuthRole = JSON.parse( JSON.stringify(_data.data).replace(/menuTitle/g, "label"));   
            this.getArrayValue(this.listCanAuthRole);
            
          }
          return true;
        },
      });
    },


    // 查询全部权限ID,转成数字类型
    getArrayValue(array){
        for(let i=0; i<array.length; i++){
           array[i].id = Number(array[i].id);
           
           if(array[i].children.length >= 1){
              this.getArrayValue(array[i].children);
           }

        }
    },  


    handleNodeClick(data) {
      let array = this.$refs.tree.getCheckedKeys();
      this.form.menuIds = [];
      for (let arr of array) {
        this.form.menuIds.push(Number(arr));
      }

    //点击切换没有清空数据
    //  console.log(this.form.menuIds);
    //  console.log(this.$refs.tree.getCheckedKeys());
    },
  },
  mounted() {
    this.init();
  },
  activated() {},
  filters: {
  menuIdsNumber: function (value) {
    for(let i=0; i<value.length; i++){
      value[i] = Number(value[i])
    }
    return value
  }
}
};
</script>
